package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPostMenu;
import com.ruoyi.system.service.ISysPostMenuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位与菜单关系信息Controller
 *
 * @author youde
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/system/postmenu")
public class SysPostMenuController extends BaseController {
    @Autowired
    private ISysPostMenuService sysPostMenuService;

/**
 * 查询岗位与菜单关系信息列表
 */
@PreAuthorize("@ss.hasPermi('system:postmenu:list')")
@GetMapping("/list")
    public TableDataInfo list(SysPostMenu sysPostMenu) {
        Page<SysPostMenu> list = sysPostMenuService.selectSysPostMenuList(sysPostMenu, startPage());
        return getDataTable(list);
    }

    /**
     * 导出岗位与菜单关系信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:postmenu:export')")
    @Log(title = "岗位与菜单关系信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPostMenu sysPostMenu) {
        List<SysPostMenu> list = sysPostMenuService.selectSysPostMenuList(sysPostMenu);
        ExcelUtil<SysPostMenu> util = new ExcelUtil<SysPostMenu>(SysPostMenu. class);
        util.exportExcel(response, list, "岗位与菜单关系信息数据");
    }

    /**
     * 获取岗位与菜单关系信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:postmenu:query')")
    @GetMapping(value = "/{postMenuId}")
    public AjaxResult getInfo(@PathVariable("postMenuId") String postMenuId) {
        return AjaxResult.success(sysPostMenuService.selectSysPostMenuByPostMenuId(postMenuId));
    }

    /**
     * 新增岗位与菜单关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:postmenu:add')")
    @Log(title = "岗位与菜单关系信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPostMenu[] sysPostMenu) {
        return AjaxResult.success(sysPostMenuService.insertSysPostMenu(sysPostMenu));
    }

    /**
     * 修改岗位与菜单关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:postmenu:edit')")
    @Log(title = "岗位与菜单关系信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPostMenu sysPostMenu) {
        return AjaxResult.success(sysPostMenuService.updateSysPostMenu(sysPostMenu));
    }

    /**
     * 删除岗位与菜单关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:postmenu:remove')")
    @Log(title = "岗位与菜单关系信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{postMenuIds}")
    public AjaxResult remove(@PathVariable String[] postMenuIds) {
        sysPostMenuService.deleteSysPostMenuByPostMenuIds(postMenuIds);
        return AjaxResult.success();
    }

    /**
     * 删除岗位与菜单关系信息
     */
    @PreAuthorize("@ss.hasPermi('system:postmenu:remove')")
    @Log(title = "岗位与菜单关系信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/postId/{postId}")
    public AjaxResult removeByPostId(@PathVariable String postId) {
        sysPostMenuService.deleteByPostId(postId);
        return AjaxResult.success();
    }

}